<?php
namespace Home\Controller;
use Think\Controller;
class PayController extends CommonController {
	public function pay(){
		$Address=M('Address');
		$addr=$Address->where("user_id={$_SESSION['user_id']} and status=1")->find();
		$Shopcart = M ("Shopcart");
		$res = $Shopcart->where("user_id={$_SESSION['user_id']} and selected = 1")->select();
		if($res != false){
			$data=array();		
			foreach($res as $val){
				$Shop = M ('Shop');
				$list = $Shop->where("shop_id={$val['shop_id']}")->find();
				$picture = $list['picture'];
				$var = json_decode($picture);
				$arr = explode("/",$val['kouwei']);
				$val['picture']=$var[0];
				$val['title']=$list['title'];
				$val['kouwei']=$arr;
				$val['cxprice']=$list['cxprice'];
				$val['num']=$val['count']*$list['cxprice'];
				$data[]=$val;
			}
			$this->assign("data",$data);
		}
		$this->assign("addr",$addr);
		$this->display('pay');	
	}
	public function success(){
		$num = I ("get.sum");
		$addr_id = I ("get.addr_id");
		$Address = M ("Address");
		$res = $Address->where("addr_id={$addr_id}")->find();
		$this->assign("num",$num);
		$this->assign("res",$res);
		$Shopcart = M ("Shopcart");
		$data=array(
			'status' =>2
		);
		$res = $Shopcart->where("user_id={$_SESSION['user_id']} and selected = 1 and status = 1")->setField($data);
		if($res == false){
			exit;
		}else{
			$this->display('success');
		}	
	}
}
